﻿@using PagedList
@using PagedList.Mvc;
@using TestOnlineProject.Models.Entities
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Question</h3>
</div>
<div class="modal-body">
    <div>
        @using (Ajax.BeginForm("PopupQuestion", "Discussion", new AjaxOptions
        {
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "GET",
            UpdateTargetId = "question",
        }, new {@class = "form-inline"}))
        {
            @Html.Hidden("subjectId", "", new { value = @ViewBag.SubjectId })
            @Html.TextBox("keyWord", "", new { placeholder = "Content Question", value = @ViewBag.KeyWord })
            <input type="submit" value="Search" class="btn" />
        }
    </div>
    @if (@ViewBag.Question != null)
    {
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th></th>
                    <th>No.</th>
                    <th>Content</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in (IEnumerable<Question>) @ViewBag.Question)
                {
                    <tr>
                        <td>
                            <input type="checkbox" value="@item.QuestionId" class="is_selected"/>
                        </td>
                        <td>
                            @{
                                var noList = ViewBag.NoList as List<NoModel>;
                                var no = noList.FirstOrDefault(n => n.Id == item.QuestionId).No;
                                <span style="word-wrap: break-word">@no</span>
                            }
                        </td>
                        <td>
                            @Html.Raw(@item.Content)
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        @Html.PagedListPager((IPagedList) @ViewBag.Question, page => Url.Action("PopupQuestion", new { page, subjectId = @ViewBag.SubjectId }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "question", OnComplete = "" }))
    }
</div>
<div class="modal-footer">
    <button class="btn btn-primary" name="Add">Add question</button>
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
